<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>移动端适配</title>

    <style>
        /* html {
            font-size: 20px;
        
        } */

        .box-px {
        width: 300px;
        height: 100px;
        background-color: pink;
        margin-bottom: 50px;
        }
        .box-rem {
        width: 5rem;
        height: 3rem;
        background-color: black;
        }
    </style>
</head>
<body>
    <div class="box-px"></div>
    <div class="box-rem"></div>

    <script>
        //根据设备宽度计算HTML标签的 font-size 的属性值，设为设备宽度的1/10
        function resetHtmlFontSize(){
            document.documentElement.style.fontSize = screen.width/10 + 'px'
        }
        resetHtmlFontSize();
        window.onresize = resetHtmlFontSize;

    </script>
</body>
</html>